package com.ruoyi.wretchant.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wretchant.domain.MetaWechat;
import com.ruoyi.wretchant.service.IMetaWechatService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微信好友Controller
 * 
 * @author 简简单单 Online zuozuo
 * @date 2021-08-18
 */
@Controller
@RequestMapping("/wretchant/wechat")
public class MetaWechatController extends BaseController
{
    private String prefix = "wretchant/wechat";

    @Autowired
    private IMetaWechatService metaWechatService;

    @RequiresPermissions("wretchant:wechat:view")
    @GetMapping()
    public String wechat()
    {
        return prefix + "/wechat";
    }

    /**
     * 查询微信好友列表
     */
    @RequiresPermissions("wretchant:wechat:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MetaWechat metaWechat)
    {
        startPage();
        List<MetaWechat> list = metaWechatService.selectMetaWechatList(metaWechat);
        return getDataTable(list);
    }

    /**
     * 导出微信好友列表
     */
    @RequiresPermissions("wretchant:wechat:export")
    @Log(title = "微信好友", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MetaWechat metaWechat)
    {
        List<MetaWechat> list = metaWechatService.selectMetaWechatList(metaWechat);
        ExcelUtil<MetaWechat> util = new ExcelUtil<MetaWechat>(MetaWechat.class);
        return util.exportExcel(list, "微信好友数据");
    }

    /**
     * 新增微信好友
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存微信好友
     */
    @RequiresPermissions("wretchant:wechat:add")
    @Log(title = "微信好友", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MetaWechat metaWechat)
    {
        return toAjax(metaWechatService.insertMetaWechat(metaWechat));
    }

    /**
     * 修改微信好友
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MetaWechat metaWechat = metaWechatService.selectMetaWechatById(id);
        mmap.put("metaWechat", metaWechat);
        return prefix + "/edit";
    }

    /**
     * 修改保存微信好友
     */
    @RequiresPermissions("wretchant:wechat:edit")
    @Log(title = "微信好友", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MetaWechat metaWechat)
    {
        return toAjax(metaWechatService.updateMetaWechat(metaWechat));
    }

    /**
     * 删除微信好友
     */
    @RequiresPermissions("wretchant:wechat:remove")
    @Log(title = "微信好友", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(metaWechatService.deleteMetaWechatByIds(ids));
    }
}
